﻿using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using Noke.Common;
using System.Collections.Generic;
using System.Reflection;
using System.ServiceProcess;
using System.Diagnostics;
using Noke.SOA.Service;


namespace Noke.SOA.Test.Service
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0 && args[0] == "-d")
            {
                try
                {                    
                    SOAService service = SOAService.GetIncident();
                    service.InitService(typeof(Program));
                    service.Start();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
            }
            else
            {
                string rs = Console.ReadLine();
                switch (rs)
                {
                    case "-i":
                        //取当前可执行文件路径，加上"s"参数，证明是从windows服务启动该程序
                        var path = Process.GetCurrentProcess().MainModule.FileName + " s";
                        Process.Start("sc", "create  noke_soa_racer_service binpath= \"" + path + "\" displayName=noke_soa_racer_service start= auto");
                        Console.WriteLine("安装成功");
                        Console.Read();
                        break;
                    case "-u":
                        Process.Start("sc", "delete noke_soa_racer_service");
                        Console.WriteLine("卸载成功");
                        Console.Read();
                        break;
                    case "-s":
                        ServiceBase[] ServicesToRun;
                        ServicesToRun = new ServiceBase[] { new ProjectService() };
                        ServiceBase.Run(ServicesToRun);
                        break;
                }
            }

            Console.ReadLine();
        }


    }
}
